package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.article.ApAuthorControllerApi;
import com.heima.article.service.ApAuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements ApAuthorControllerApi {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 文章作者添加用户
     * @param apAuthor
     * @return
     */
    @PostMapping("/seveApAuthor")
    @Override
    public ResponseResult seveApAuthor(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.seveApAuthor(apAuthor);
    }

    /**
     * 根据作者名称查询作者信息
     *
     * @param name
     * @return
     */
    @GetMapping("/findByName/{name}")
    @Override
    public ApAuthor selectAuthorByName(@PathVariable("name") String name) {
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getName, name));
    }

    /**
     * 根据Id查询作者
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id") Integer id) {
        return apAuthorService.getById(id);
    }

}
